package com.assignwork.modules.inportship;

import com.assignwork.dto.VoyageBillCabinSearchDTO;
import com.assignwork.dto.VoyageBillCabinSubmitByCabinDTO;
import com.assignwork.dto.VoyageBillCabinSubmitDTO;
import com.assignwork.service.IVoyageBillCabinService;
import com.assignwork.vo.BillAllCabinPageVO;
import com.assignwork.vo.VoyageBillCabinSimpleVO;
import com.assignwork.vo.VoyageBillSplitCabinPageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @ClassName VoyageBillCabinController
 * @Description 舱单信息控制器
 * @Author dujianyu
 * @Date 2023/8/24 9:39
 */
@RestController
@AllArgsConstructor
@RequestMapping("voyageBillCabin")
public class VoyageBillCabinController extends BladeController {

    private IVoyageBillCabinService service;

    @GetMapping("/allPage")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "全部分页", notes = "传入dto")
    public R<IPage<BillAllCabinPageVO>> allPage(VoyageBillCabinSearchDTO dto, Query query) {
        return R.data(service.selectVoyageBillCabinAllPage(dto, Condition.getPage(query)));
    }

    @GetMapping("/billPage")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "票分页", notes = "传入dto")
    public R<IPage<VoyageBillCabinSimpleVO>> billPage(VoyageBillCabinSearchDTO dto, Query query) {
        return R.data(service.selectVoyageBillCabinBillPage(dto, Condition.getPage(query)));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入dto")
    public R<VoyageBillCabinSimpleVO> detail(VoyageBillCabinSearchDTO dto) {
        return R.data(service.detail(dto));
    }

    @GetMapping("/cabinPage")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "舱分页", notes = "传入dto")
    public R<IPage<VoyageBillSplitCabinPageVO>> splitCabinPage(VoyageBillCabinSearchDTO dto, Query query) {
        return R.data(service.selectVoyageBillSpiltCabinPage(dto, Condition.getPage(query)));
    }

    @PostMapping("submit")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "新增或修改", notes = "传入dto")
    public R<Boolean> submitVoyageBillCabin(@RequestBody VoyageBillCabinSubmitDTO dto) {
        return R.status(service.submitVoyageBillCabin(dto));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        return R.status(service.deleteLogic(Func.toLongList(id)));
    }

    @PostMapping("submitByCabin")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "通过舱号新增或修改", notes = "传入dto")
    public R<Boolean> submitByCabin(@RequestBody VoyageBillCabinSubmitByCabinDTO dto) {
        return R.status(service.submitByCabin(dto));
    }

    @GetMapping("/getTallyTon")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "获取理货吨", notes = "传入dto")
    public R<BigDecimal> getTallyTon(VoyageBillCabinSearchDTO dto) {
        return R.data(service.getTallyTon(dto));
    }
}
